package com.chengqs.service.Impl;

import com.chengqs.mapper.UserMapper;
import com.chengqs.pojo.entity.User;
import com.chengqs.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String email) {
        //因为此处的业务逻辑比较简单,所以直接调用mapper结束
        User user = userMapper.findByEmail(email);
        //进一步要去确认user的一些信息.
        //TODO... 还需要很多的业务逻辑的处理
        return userMapper.findByEmail(email);
    }

    @Override
    public PageInfo<User> pageInfo(Integer pageNum, Integer pageSize) {
        //必须先设置分页的参数
        PageHelper.startPage(pageNum,pageSize);
        //调用mapper - 查看所有的
        List<User> users = userMapper.findAll();
        //pageInfo这个对象封装了所有关于分页的信息
        PageInfo<User> pageInfo = new PageInfo<>(users);

        return pageInfo;
    }
}
